/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.entity


import com.ages.graphics.AnimatedSprite
import javax.media.opengl.GL
import scala.xml.Elem
import scala.xml.XML

class Model(filename:String) extends Actor{

  val file = getClass.getResource(filename).getFile
  val xml:Elem = XML.loadFile(file)
  val imgSrc = ((xml \\ "img") \\ "@src").text
  val sheet = new AnimatedSprite(imgSrc)

  var base = new Joint("NOT_INITIALIZED!ERROR!",0)
  for (x<- xml \ "joint")
  {
    val frameNum = Integer.parseInt(x.attribute("frame").get.toString)
    base = new Joint(x.attribute("name").get.toString,frameNum)
    buildModel(x.asInstanceOf[Elem],base)
  }
  println(base.flatList)

  def think(){}
  def draw(gl:GL)
  {
    
  }

  def buildModel(e:Elem,j:Joint)
  {
    for(x <- e \ "joint")
    {
      val frameNum = Integer.parseInt(x.attribute("frame").get.toString)
      val name = x.attribute("name").get.toString
      val newJoint = new Joint(name,frameNum)
      j.addJoint(newJoint)
      buildModel(x.asInstanceOf[Elem],newJoint)
    }
  }


  
}
